package com.wfl.sampling.service;

import com.wechat.pay.contrib.apache.httpclient.auth.Verifier;
import com.wfl.sampling.handler.WxChatResponseInfo;
import okhttp3.HttpUrl;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.SignatureException;
import java.security.spec.InvalidKeySpecException;
import java.util.Map;

public interface WxchatSignService {
    // Authorization: <schema> <token>
    // GET - getToken("GET", httpurl, "")
    // POST - getToken("POST", httpurl, json)
    //获取请求签名
    String getSign(String method, HttpUrl url, String body) throws NoSuchAlgorithmException, SignatureException, InvalidKeySpecException, InvalidKeyException, UnsupportedEncodingException;

    String getToken( String method, HttpUrl url, String body) throws IOException, NoSuchAlgorithmException, InvalidKeyException, SignatureException;

    String sign( byte[] message) throws IOException, NoSuchAlgorithmException, InvalidKeyException, SignatureException;

    String buildMessage(String method, HttpUrl url, long timestamp, String nonceStr, String body);


    String bulidMessagePay(String appid, String nonceStr, String Package, String timeStamp);


    //生成微信支付请求
    WxChatResponseInfo WxChatdoPay(String mothed, String url, Map<String, Object> param) throws UnsupportedEncodingException, NoSuchAlgorithmException, SignatureException, InvalidKeySpecException, InvalidKeyException;

    //生成微信查询（订单，退款）请求
    WxChatResponseInfo WxChatQuery(String queryType, String out_trade_no) throws URISyntaxException, UnsupportedEncodingException, NoSuchAlgorithmException, SignatureException, InvalidKeySpecException, InvalidKeyException, MalformedURLException;

    //关闭订单请求
    Map<String, Integer> WxChatClose(String out_trade_no) throws  UnsupportedEncodingException, NoSuchAlgorithmException, SignatureException, InvalidKeySpecException, InvalidKeyException;

    //获取验证签名器
    Verifier getVerifier() throws IOException;

    //签证签名
    boolean wxPaySuccessCallback(HttpServletRequest request, HttpServletResponse response, Verifier verifier);

    //获取解密的回调报文
    String Outbody(Map<String, Object> bodyMap);
}
